# Huawei Technologies Co.,Ltd.

set(DYNINSTRUCTION_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dyninstruction.txt)
set(DYNINSTRUCTION_BIN ${CMAKE_CURRENT_BINARY_DIR}/dyninstruction.abc)
set(DYNINSTRUCTION_JS ${CMAKE_CURRENT_SOURCE_DIR}/dyninstruction.js)
set(DYNINSTRUCTION_VERIFY ${CMAKE_CURRENT_SOURCE_DIR}/verify.sh)

set(RUNTIME_ARGUMENTS --boot-panda-files=${PANDA_BINARY_ROOT}/pandastdlib/arkstdlib.abc --load-runtimes=\"ecmascript\" --compiler-enable-jit=false ${DYNINSTRUCTION_BIN} _GLOBAL::func_main_0)

add_custom_command(
    OUTPUT ${DYNINSTRUCTION_OUTPUT}
    COMMENT "running javascript dyninstruction testcase"
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:es2panda> ${DYNINSTRUCTION_JS} --output ${DYNINSTRUCTION_BIN}
    COMMAND rm -f ${DYNINSTRUCTION_OUTPUT}
    COMMAND ${PANDA_RUN_PREFIX} $<TARGET_FILE:ark> ${RUNTIME_ARGUMENTS} > ${DYNINSTRUCTION_OUTPUT}
    COMMAND bash ${DYNINSTRUCTION_VERIFY} ${DYNINSTRUCTION_OUTPUT}
)
add_custom_target(dyninstruction
    DEPENDS ${DYNINSTRUCTION_OUTPUT} ${DYNINSTRUCTION_VERIFY}
)
add_dependencies(dyninstruction es2panda ark)
add_dependencies(ecmascript_common_tests dyninstruction)
